package com.bw.servlet;

import com.bw.dao.PhoneDao;
import com.bw.pojo.Phone;
import lombok.SneakyThrows;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/***************************
 FileAction:

 CreateTime:2022-05-11 9:11
 Author:Aaking-aline
 ****************************/
@WebServlet("/AddPhoneServlet")
public class AddPhoneServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	@SneakyThrows
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 这里获取 手机的信息 然后添加到数据库里
		Map<String, String[]> map = request.getParameterMap();
		Phone phone = new Phone();

		BeanUtils.populate(phone,map);

		System.out.println(phone);


		new PhoneDao().insertPhone(phone);

		response.sendRedirect("message.jsp");

	}
}
